<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

$section_id = mysql_real_escape_string(strip_tags($_GET['sec_id']));
$query = "SELECT *, csm.id AS csm_id, c.id AS cid, csub.id AS sid
 		  FROM course_sections cs
		  JOIN course_section_mapping csm ON csm.course_section_id = cs.id
		  JOIN courses c ON c.id = csm.course_id
		  JOIN course_subjects csub ON csub.id = c.course_subject_id
		  WHERE cs.id = '$section_id'";
$result = mysql_query($query);
$row=mysql_fetch_assoc($result);
$csm_id = $row['csm_id'];
$course_id = $row['cid'];
$subject_id = $row['sid'];

$get_subject_data = mysql_query("SELECT * FROM course_subjects WHERE id = $subject_id");
$subject_name = mysql_result($get_subject_data,0,'subject_title');
$abbreviation = mysql_result($get_subject_data,0,'abbreviation');

$get_course_data = mysql_query("SELECT * FROM courses WHERE id = $course_id");
$course_number = mysql_result($get_course_data,0,'course_number');
$course_name = mysql_result($get_course_data,0,'title');

$get_section_data = mysql_query("SELECT * FROM course_sections WHERE id = $section_id");
$section_number = mysql_result($get_section_data,0,'section_number');

//counting variable
$i = 0;

$formatted_section_number = sprintf("%03d", $section_number);

echo "<p>";
	echo "<a href='index.php?sid=$subject_id&csm_id=$csm_id&cid=$course_id&sec_id=$section_id'>&lt;&lt; Back to Section Crosslisting Portal</a><br />";
echo "</p>";
echo "<h1>Add Crosslisting for $abbreviation $course_number - $formatted_section_number</h1>";

$query="SELECT *
		FROM courses
		JOIN course_subjects
		ON courses.course_subject_id=course_subjects.id
		ORDER BY course_subjects.abbreviation, courses.course_number";
$result=mysql_query($query);

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);


echo '<p>';

$classroom_type_id = 1;

echo '<form action="add_do.php" method="post">';

//start table
echo "<table border='0'>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Course: </b></td>";
		echo "<td>";
			echo "<select name='new_cl'>";
				while ($i < $num_rows)
				{
					$cl_course_id=mysql_result($result,$i,"courses.id");
					$cl_abbreviation=mysql_result($result,$i,"course_subjects.abbreviation");
					$cl_course_number=mysql_result($result,$i,"courses.course_number");
					$cl_course_name=mysql_result($result,$i,"courses.title");
											
					echo "<option value=$cl_course_id>$cl_abbreviation $cl_course_number - $cl_course_name</option>";
					$i++;
				}
			echo "</select>";
		echo "<td>";
	echo "</tr>";


//end table tag
echo "</table>";




echo "<input type='hidden' name='cid' value='$course_id'>";
echo "<input type='hidden' name='sid' value='$subject_id'>";
echo "<input type='hidden' name='csm_id' value='$csm_id'>";
echo "<input type='hidden' name='sec_id' value='$section_id'>";
echo '<p><input type="submit"></p>';
echo '</form>';



?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>